<?php

use Illuminate\Support\Facades\Route;

use App\Http\Controllers\Admin;
use App\Http\Middleware\JwtMiddleware;

Route::get('/', function () {
    return view('welcome');
});

// 后台管理路由
Route::prefix('admin')->group(function () {
    Route::middleware([JwtMiddleware::class])->group(function () {
        Route::controller(Admin\AuthController::class)->group(function () {
            // 排除 JwtMiddleware 中间件的路由
            Route::withoutMiddleware([JwtMiddleware::class])->group(function () {
                // 登录
                Route::post('/login', 'login');
                // 初始化 admin 账号
                Route::post('/init', 'init');
            });
            Route::post('/logout', 'logout');
            Route::get('/routes', 'routes');
        });

        Route::apiResource('/dept', Admin\DeptController::class);
        Route::apiResource('/menu', Admin\MenuController::class);

        Route::apiResource('/role', Admin\RoleController::class);
        Route::controller(Admin\RoleController::class)->group(function () {
            Route::get('/role-menu-ids/{id}', 'getRoleMenuIds');
            Route::post('/set-role-menu-ids', 'setRoleMenuIds');
            Route::get('/role-menu', 'getRoleMenu');
        });

        Route::apiResource('/user', Admin\UserController::class);
        Route::controller(Admin\UserController::class)->group(function () {
            Route::delete('/user', 'batchDelete');
            Route::get('/all-role', 'getAllrole');
            Route::get('/list-role-ids/{id}', 'getListRoleIds');
            Route::post('/set-role-ids', 'setRoleIds');
            Route::post('/user/updatePassword', 'updatePassword');
        });
    });
});
